import 'package:FlutterStudy/I10n/localStr.dart';
import 'package:FlutterStudy/demo/AnimationDemo.dart';
import 'package:FlutterStudy/demo/DialogDemo.dart';
import 'package:FlutterStudy/demo/BottomNavigationDemo.dart';
import 'package:FlutterStudy/demo/AppBarDemo.dart';
import 'package:FlutterStudy/demo/ContainerDemo.dart';
import 'package:FlutterStudy/demo/DrawerDemo.dart';
import 'package:FlutterStudy/demo/HttpDemo.dart';
import 'package:FlutterStudy/demo/StreamDemo.dart';
import 'package:FlutterStudy/demo/i18nDemo.dart';
import 'package:FlutterStudy/tabView/FormDemo.dart';
import 'package:FlutterStudy/tabView/LayoutDemo.dart';
import 'package:FlutterStudy/demo/StackDemo.dart';
import 'package:FlutterStudy/tabView/MDCDemo.dart';
import 'package:FlutterStudy/tabView/SliverDemo.dart';
import 'package:FlutterStudy/tabView/StateManagerDemo.dart';
import 'package:FlutterStudy/tabView/ViewDemo.dart';
import 'package:FlutterStudy/tabView/routerDemo.dart';
import 'package:flutter/material.dart';
import 'package:flutter_localizations/flutter_localizations.dart';
import 'package:flutter_splash_screen/flutter_splash_screen.dart';

import 'demo/RxDartDemo.dart';
import 'generated/l10n.dart';

Future<void> main() async {
  /*  WidgetsFlutterBinding.ensureInitialized();
  await FlutterLocalization.instance.ensureInitialized();
  final FlutterLocalization localization = FlutterLocalization.instance;*/
  runApp(
    MaterialApp(
      localeResolutionCallback: (locale, supportedLocales) {
        debugPrint("语言设置有变换");
        return locale;
      },
      locale: Locale("en", 'US'),
 /*     supportedLocales: [
        Locale('en', 'US'), // English
        Locale('zh', 'CH'), // Chinese
      ],*/
      supportedLocales: S.delegate.supportedLocales,
      localizationsDelegates: [
        GlobalMaterialLocalizations.delegate,
        GlobalWidgetsLocalizations.delegate,
        GlobalCupertinoLocalizations.delegate,
        AppLocalDelegete(),
        S.delegate,
      ],
      title: 'Flutter Sliver Demo',
      theme: ThemeData(
        primaryColorLight: Colors.yellow,
        primarySwatch: Colors.blue,
        appBarTheme: AppBarThemeData(
          backgroundColor: Colors.deepPurpleAccent,
          titleTextStyle: TextStyle(color: Colors.green, fontSize: 22),
        ),
        primaryColor: Colors.brown,
        splashColor: Colors.white,
        highlightColor: Colors.white,
        textTheme: TextTheme(
          titleMedium: TextStyle(fontSize: 22, color: Colors.white),
        ),
        primaryTextTheme: TextTheme(
          displayLarge: TextStyle(fontSize: 22, color: Colors.white),
          displayMedium: TextStyle(fontSize: 3, color: Colors.white),
          displaySmall: TextStyle(fontSize: 11, color: Colors.white),
        ),
        visualDensity: VisualDensity.adaptivePlatformDensity,
      ),
      home: DefaultTabController(
        length: 13,
        initialIndex: 12,
        child: Scaffold(
          appBar: _bulidAppBar(),
          body: TabBarView(
            children: [
              LayoutDemo(),
              ViewDemo(),
              SliverDemo(),
              routerDemo(),
              FormDemo(),
              DialogDemo(),
              MDCDemo(),
              StateManagerDemo(),
              StreamDemo(),
              RxDartDemo(),
              HttpDemo(),
              AnimationDemo(),
              i18nDemo(),
            ],
          ),
          /*drawer: Container(child: Center(child: Text("我是drawer")),color: Colors.white,width: 200,
          )*/
          drawer: DrawerDemo(),
          bottomNavigationBar: BottomNavigationDemo(),
        ),
      ),
      // initialRoute: "/b",
      routes: {
        // "/":(context)=>routerDemo(),
        "/a": (context) => PageDemo(titleStr: "Home"),
        "/b": (context) => PageDemo(titleStr: "Me"),
      },
    ),
  );
}

PreferredSizeWidget _bulidAppBar() {
  return AppBar(
    toolbarHeight: 100,
    title: Text("我是中间标题"),
    actions: [
      Icon(Icons.abc_outlined, size: 28),
      Icon(Icons.abc_outlined, size: 28),
      Icon(Icons.abc_outlined, size: 28),
      Icon(Icons.abc_outlined, size: 28),
      Icon(Icons.abc_outlined, size: 28),
    ],
    leading: Builder(
      builder: (context) {
        return IconButton(
          onPressed: () {
            Scaffold.of(context).openDrawer();
          },
          icon: Icon(Icons.back_hand),
        );
      },
    ),
    toolbarTextStyle: TextStyle(fontSize: 1000, color: Colors.orangeAccent),
    toolbarOpacity: 0.5,
    centerTitle: true,
    elevation: 10,
    bottom: TabBar(
      isScrollable: true,
      splashBorderRadius: BorderRadius.all(Radius.zero),
      dividerHeight: 0,
      indicatorSize: TabBarIndicatorSize.tab,
      indicator: UnderlineTabIndicator(borderRadius: BorderRadius.circular(10)),
      padding: EdgeInsets.only(bottom: 10),
      indicatorWeight: 6,
      indicatorColor: Colors.pink,
      indicatorAnimation: TabIndicatorAnimation.elastic,
      indicatorPadding: EdgeInsets.zero,
      // 移除指示器内边距
      unselectedLabelColor: Colors.yellow,
      labelColor: Colors.red,
      tabs: <Widget>[
        Tab(
          child: Row(
            children: [
              /* Expanded(
                child: Text(
                  "基本layout",
                  overflow: TextOverflow.ellipsis,
                  maxLines: 1,
                ),
              )*/
              Text("基本layout", overflow: TextOverflow.ellipsis, maxLines: 1),
              SizedBox(
                width: 12,
                height: 12,
                child: Image.asset("images/pic6.jpg", fit: BoxFit.cover),
              ),
            ],
            mainAxisAlignment: MainAxisAlignment.center,
          ),
        ),
        Tab(
          icon: ImageIcon(AssetImage("images/pic3.jpg")),
          child: Row(
            // children: <Widget>[Flexible(child: Text("视图布局"))],
            children: <Widget>[Text("视图布局")],
            mainAxisAlignment: MainAxisAlignment.center,
          ),
        ),
        Tab(child: Row(children: <Widget>[Text("sliver")])),
        Tab(child: Row(children: <Widget>[Text("路由")])),
        Tab(child: Row(children: <Widget>[Text("表单")])),
        Tab(child: Row(children: <Widget>[Text("弹窗")])),
        Tab(child: Row(children: <Widget>[Text("Material控件")])),
        Tab(child: Row(children: <Widget>[Text("状态管理")])),
        Tab(child: Row(children: <Widget>[Text("Stream")])),
        Tab(child: Row(children: <Widget>[Text("RxDart")])),
        Tab(child: Row(children: <Widget>[Text("Http请求")])),
        Tab(child: Row(children: <Widget>[Text("动画")])),
        Tab(child: Row(children: <Widget>[Text("国际化")])),
      ],
    ),
  );
}
///hide your splash screen
Future<void> hideScreen() async {
  Future.delayed(Duration(milliseconds: 1800), () {
    FlutterSplashScreen.hide();
  });
}
